using Entity.Monster.State;
using MoonFramework.FSM;

namespace Entity.Monster
{
    public class MonsterFsm: BaseFsm<Actor>
    {
        public override void Init(string curState, Actor entity)
        {
            base.Init(curState, entity);
            _ = AllocateState(nameof(MonsterIdleState), () => new MonsterIdleState(), InitState);
            _ = AllocateState(nameof(MonsterDeadState), () => new MonsterDeadState(), InitState);
            _ = AllocateState(nameof(MonsterRunState), () => new MonsterRunState(), InitState);
            _ = AllocateState(nameof(MonsterAttackState), () => new MonsterAttackState(), InitState);
            _ = AllocateState(nameof(MonsterWalkState), () => new MonsterWalkState(), InitState);
            _ = AllocateState(nameof(MonsterHurtState), () => new MonsterHurtState(), InitState);
            
            AddTransition(nameof(MonsterIdleState), nameof(MonsterWalkState));
            AddTransition(nameof(MonsterIdleState), nameof(MonsterDeadState));
            AddTransition(nameof(MonsterIdleState), nameof(MonsterHurtState));

            AddTransition(nameof(MonsterAttackState), nameof(MonsterRunState));
            AddTransition(nameof(MonsterAttackState), nameof(MonsterDeadState));
            AddTransition(nameof(MonsterAttackState), nameof(MonsterHurtState));
            
            AddTransition(nameof(MonsterWalkState), nameof(MonsterIdleState));
            AddTransition(nameof(MonsterWalkState), nameof(MonsterRunState));
            AddTransition(nameof(MonsterWalkState), nameof(MonsterDeadState));
            AddTransition(nameof(MonsterWalkState), nameof(MonsterHurtState));

            AddTransition(nameof(MonsterRunState), nameof(MonsterWalkState));
            AddTransition(nameof(MonsterRunState), nameof(MonsterAttackState));
            AddTransition(nameof(MonsterRunState), nameof(MonsterDeadState));
            AddTransition(nameof(MonsterRunState), nameof(MonsterHurtState));
            
            AddTransition(nameof(MonsterHurtState), nameof(MonsterRunState));
            AddTransition(nameof(MonsterHurtState), nameof(MonsterAttackState));
            AddTransition(nameof(MonsterHurtState), nameof(MonsterWalkState));
            AddTransition(nameof(MonsterHurtState), nameof(MonsterDeadState));
            AddTransition(nameof(MonsterHurtState), nameof(MonsterIdleState));
            
            fsmStates[curState].Enter();
        }
        
        private void InitState(BaseState state)
        {
            state.Init(this);
        }
    }
}